﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ShenRuQianChuWPFChapt7
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        Student stu;
        public MainWindow()
        {
            InitializeComponent();

            stu = new Student();
            stu.SetBinding(Student.NameProperty, new Binding("Text") { Source = textBox1 });
            textBox2.SetBinding(TextBox.TextProperty, new Binding("Name") { Source = stu });
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Student stu = new Student();
            //stu.SetValue(Student.NameProperty,this.textBox1.Text);
            //textBox2.Text = (string)stu.GetValue(Student.NameProperty);

            stu = new Student();
            ////让textBox1作为数据源对象并从其属性中获取数据
            //Binding binding = new Binding("Text") { Source = textBox1 };
            ////指定将stu对象借助刚刚声明的binding实例依赖在textBox1上
            //BindingOperations.SetBinding(stu, Student.NameProperty, binding);

            //textBox2.SetBinding(TextBox.TextProperty, binding);
            //MessageBox.Show(stu.GetValue(Student.NameProperty).ToString());

            stu.Name = this.textBox1.Text;
            this.textBox2.Text = stu.Name;

        }
    }
}
